/**
 * File:   assets_preload_view_model.h
 * Author: AWTK Develop Team
 * Brief:  assets_preload_view_model
 *
 * Copyright (c) 2023 - 2024  Guangzhou ZHIYUAN Electronics Co.,Ltd.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * License file for more details.
 *
 */

/**
 * History:
 * ================================================================
 * 2024-3-08 Li XianJing <xianjimli@hotmail.com> created
 *
 */

#ifndef TK_ASSETS_PRELOAD_VIEW_MODEL_H
#define TK_ASSETS_PRELOAD_VIEW_MODEL_H

#include "tkc/object.h"
#include "conf_io/conf_node.h"
#include "modbus_client_channel.h"

BEGIN_C_DECLS

/**
 * @class assets_preload_view_model_t
 * @parent tk_object_t
 * 资源预先加载。
 */
typedef struct _assets_preload_t {
  tk_object_t object;

  /*private*/
  conf_doc_t* doc;
  bool_t done;
  uint32_t index;
  uint32_t total;
  uint32_t timer_id;
  conf_node_t* current;
} assets_preload_t;

/**
 * @method assets_preload_view_model_init
 * 初始化。
 *
 * @return {ret_t} 返回RET_OK表示成功，否则表示失败。
 */
ret_t assets_preload_view_model_init(void);

/**
 * @method assets_preload_view_model_deinit
 * 反初始化。
 *
 * @return {ret_t} 返回RET_OK表示成功，否则表示失败。
 */
ret_t assets_preload_view_model_deinit(void);

#define ASSETS_PRELOAD_VIEW_MODEL_PROP_TOTAL "total"
#define ASSETS_PRELOAD_VIEW_MODEL_PROP_DONE "done"
#define ASSETS_PRELOAD_VIEW_MODEL_PROP_PROGRESS "progress"
#define ASSETS_PRELOAD_VIEW_MODEL_PROP_CURRENT_INDEX "current_index"
#define ASSETS_PRELOAD_VIEW_MODEL_PROP_CURRENT_NAME "current_name"
#define ASSETS_PRELOAD_VIEW_MODEL_PROP_CURRENT_TYPE "current_type"

#define ASSETS_PRELOAD_VIEW_MODEL_CMD_START "start"
#define ASSETS_PRELOAD_VIEW_MODEL_CMD_ABORT "abort"

/*public for test*/
/**
 * @method assets_preload_view_model_create
 * 创建assets_preload_view_model对象。
 *
 * @annotation ["constructor"]
 * @return {tk_object_t*} 返回assets_preload_view_model对象。
 */
tk_object_t* assets_preload_view_model_create_with_name(const char* name);

/**
 * @method assets_preload_step
 * 预加载一个。
 * @param {assets_preload_t*} preload assets_preload对象。
 * 
 * @return {ret_t} 返回RET_OK表示成功，否则表示失败。
 */
ret_t assets_preload_step(assets_preload_t* preload);

END_C_DECLS

#endif /*TK_ASSETS_PRELOAD_VIEW_MODEL_H*/
